package Jedis.JedisExample.servlet;

import Jedis.JedisExample.domain.Province;
import Jedis.JedisExample.servince.ProvinceServince;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet( "/provinceServlet")
public class findprovinceServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.调用service查询
        ProvinceServince aa=new ProvinceServince();
        List<Province> bb = aa.findAll();
        //2.序列化list为json
        ObjectMapper cc=new ObjectMapper();
        String dd = cc.writeValueAsString(bb);
        System.out.println(dd);
        //3.响应结果
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(dd);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      this.doPost(request, response);
    }
}
